﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Net;
using System.Text;
using System.Net.Sockets;

namespace BerkelyAlgorithem2
{
    public partial class Form2 : Form
    {

        public Form1 f1;
        private NeighbourTable nt;
        public Form2(Form1 f)
        {
            InitializeComponent();
            f1 = f;

            f1.Visible = false;
            this.nt = new NeighbourTable();

            this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(checkKeys);
            this.ShowDialog();
        }

        private void checkKeys(object sender, System.Windows.Forms.KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)13)
            {
                button1_Click_1(sender, e);
            }
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }
        private void button1_Click_1(object sender, EventArgs e)
        {
            nt.addNeighbour(textBox1.Text);
            this.textBox1.Text = string.Empty;
        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            this.Visible = false;
            f1.selectionFinished(nt);
            this.Close();
        }

        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            base.OnFormClosing(e);

            e.Cancel = true;
            GC.Collect();
            GC.WaitForPendingFinalizers();


        }
    }
}
